/*----------------------------------------------------------------------------

	Copyright (c) 2006, Creator of the Cant Project.
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:

	+ Redistributions of source code must retain the above copyright notice,
	this list of conditions and the following disclaimer.

	+ Redistributions in binary form must reproduce the above copyright notice,
	this list of conditions and the following disclaimer in the documentation
	and/or other materials provided with the distribution.

	+ Neither the name of the Creator of the Cant Project nor the names of its
	contributors may be used to endorse or promote products derived from this
	software without specific prior written permission.

	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
	AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
	ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
	LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
	CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.

----------------------------------------------------------------------------*/

#ifndef	_PROJLIST_HPP_
#define	_PROJLIST_HPP_

#include	<map>
#include	<string>

#include	"except.hpp"
#include	"project.hpp"



class Project;



/**
	Container for loaded <code>Project</code> objects.
	
	Each <code>Project</code> object is indexed by its name, as given as an
	attribute of the project in its build file.
	
	
	@version	0.1
	@author		<a href="mailto:cant.project@gmail.com">Mikey</a>
*/
class ProjectList	: private std::map<std::string,Project*>
{
	public:
		/**
			Simplified type for internally maintained map.
			
		*/
		typedef	std::map<std::string,Project*>	typeProjectMap;
		
		
		/**
			Iterator type.
			
		*/
		typedef	std::map<std::string,Project*>::const_iterator	const_iterator;
		typedef	std::map<std::string,Project*>::iterator		iterator;
		
	
	public:
		/**
			Destructor.
			
			Releases all <code>Project</code> pointers.
		*/
		~ProjectList() throw();
		
		
		/**
			Adds a <code>Project</code> to the list.
			
			@param		a_strName		name of project.
			@param		a_project		pointer to project.
		*/
		void	add(const std::string& a_strName, Project* );
		
		
		/**
			Indicates whether a named <code>Project</code> is in the list.
			
			@param		a_strName		name of project.
			@return		pointer to named project if found,
						otherwise <code>null</code>.
		*/
		Project*	contains(const std::string& a_strName );
		
		
		/**
			Gives a reference to a named project.
			
			@param		a_strName		name of project.
			@return		pointer to named project.
			
			@throws		<code>ProjectException</code> if the named project is
						not found.
		*/
		Project*	get(const std::string& a_strName );
		
		
		/**
			Removes a named <code>Project</code>.
			
			Memory for the <code>Project</code> pointer is released.
			
			@param		a_strName		name of project.
		*/
		void	remove(const std::string& a_strName );
		
		
		/**
			Removes all elements.
			
			Memory for all <code>Project</code> pointers is released.
		*/
		void	clear(void );
		
		
		/**
			Gives the number of <code>Project</code> objects in the list.
			
			@return		object count.
		*/
		int	size(void ) const;
		
		
		/**
			Gives an iterator beginning of range.
			
			@return		iterator.
		*/
		iterator	begin(void );
		
		
		/**
			Gives a constant iterator beginning of range.
			
			@return		iterator.
		*/
		const_iterator	begin(void ) const;
		
		
		/**
			Gives an iterator past end of range.
			
			@return		iterator.
		*/
		iterator	end(void );
		
		
		/**
			Gives a constant iterator past end of range.
			
			@return		iterator.
		*/
		const_iterator	end(void ) const;
};

#endif
